package A_review.review0105;

import A_review.review9_13.Class131;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class Class132 {


      List<List<String>>  ans=new ArrayList<>();
      LinkedList<String>  path=new LinkedList<>();
    public List<List<String>> partition(String s) {
        //TODO:2024/1/5  判断条件没写
        if (s.length()==0){
            return  ans;
        }

       backTracking(s,0);
        return   ans;
    }

    public  void   backTracking(String s,int  start){

        if (start>=s.length()){
            ans.add(new ArrayList<>(path));
            //TODO:2024/1/5 没写这个return
            return;
        }
        for (int i = start; i <s.length() ; i++) {
            String substring = s.substring(start, i + 1);
            if (judge(substring)){
                path.add(substring);
            }else {
                continue;
            }
            backTracking(s,i+1);
            path.removeLast();
        }

    }


    public   boolean   judge(String s){
        int len = s.length();
        int end=len-1;
        int sta=0;
        while (end>sta&&end>=0&&sta<len){
            if (s.charAt(sta)==s.charAt(end)){
                sta++;
                end--;
            }else {
                return  false;
            }
        }
        return  true;
    }

    public static void main(String[] args) {
        Class131 class131 = new Class131();
        List<List<String>> aab = class131.partition("aab");
        System.out.println(aab.toString());
    }
}
